#include <bits/stdc++.h>
#define rg register
#define pc putchar
#define gc getchar
#define pf printf
#define space pc(' ')
#define enter pc('\n')
#define me(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define FOR(i,k,n,p) for(rg int i(k) ; i <= n ; i += p)
#define ROF(i,k,n,p) for(rg int i(k) ; i >= n ; i -= p)
using namespace std;
const int N = 8e5+5 ;
const int INF = 1e9+7 ;
int n,sum,top ;
int num[2][N],ti[2][N],wi[2][N],l[2][N],cs[2][N],tmd[2][N] ;
int vis[N],js[N],sz[N],val[N],st[N],wh[N] ;
struct E{int v,w,id ;}sta[N];
vector<E>e[N] ;
inline double Time()
{
	return (double)clock()/CLOCKS_PER_SEC;
}
inline void read(int &x)
{
	x = 0 ;rg int f(0) ; rg char c(gc()) ;
	while(!isdigit(c)) f |= (c=='-'),c = gc() ;
	while(isdigit(c)) x = (x<<1)+(x<<3)+(c^48),c = gc() ;
	x = (f?-x:x) ;
}
int stk[30],tp ;
inline void print(int x){
	if(x < 0) pc('-'),x = -x ;
	do stk[++tp] = x%10,x /= 10 ; while(x) ;
	while(tp) pc(stk[tp--]^48) ;
}
int Dfs(int x,int mi)
{
	int t = mi,w = 0 ;
	vis[x] = 1 ; 
	for(auto v:e[x])
	{
		if(vis[v.v]) continue ;
		mi = min(mi,v.w),js[v.id] += Dfs(v.v,mi)+mi ;
		sum += mi,w += js[v.id],mi = t ;
	}
	return w ;
}
inline void Calc(int x)
{
	FOR(i,1,n,1) vis[i] = 0 ;
	Dfs(x,INF) ;
	FOR(i,1,n,1) val[i] += js[i],js[i] = 0 ;
}
void La(int x)
{
	vis[x] = 1 ;
	for(auto v:e[x])
	{
		if(vis[v.v]) continue ;
		sta[++top] = v,La(v.v) ;
	}
}
inline void Solve(int x)
{
	if(x) FOR(i,1,n,1)
		swap(sta[i],sta[n-i+1]) ;
	top = 0 ;
	FOR(i,1,n,1)
	{
		while(sta[st[top]].w < sta[i].w && top) --top ;
		l[x][i] = st[top],st[++top] = i ;		
	}
	if(x) FOR(i,1,n,1) l[x][i] = n-l[x][i]+1 ;
}
int main()
{
    freopen("tatooine.in","r",stdin) ;
    freopen("tatooine.out","w",stdout) ;
 	read(n) ;
 	FOR(i,1,n-1,1)
 	{
 		int u,v,w ;
 		read(u),read(v),read(w) ;
 		e[u].pb({v,w,i}),e[v].pb({u,w,i}) ;
	 }
	if(n <= 2e3)
	{
		FOR(i,1,n,1) Calc(i) ;
		FOR(i,1,n-1,1) print((sum-val[i])/2),enter ;
	}
	else
	{
		La(1),n-- ;
		Solve(0),Solve(1) ;
		FOR(i,1,n,1) wh[sta[i].id] = i ;
		FOR(i,1,n,1) sum += (l[1][i]-l[0][i])*sta[i].w ;
		FOR(i,1,n,1)
		{
			int v = (l[1][i]-l[0][i])*sta[i].w ;
			num[0][i] += l[0][i] ;
			ti[0][i] += sta[i].w ;
			wi[0][i] += v ; 
			cs[0][i]++ ;
			tmd[0][i] += l[0][i]*sta[i].w ;
			num[0][l[1][i]] -= l[0][i] ;
			ti[0][l[1][i]] -= sta[i].w ;
			wi[0][i] -= v ;
			cs[0][l[1][i]]-- ;
			tmd[0][l[1][i]] -= l[0][i]*sta[i].w ;
		}
		FOR(i,1,n,1) 
		{
			int v = (l[1][i]-l[0][i])*sta[i].w ;
			num[1][i] += l[1][i] ;
			ti[1][i] += sta[i].w ;
			wi[1][i] += v ;
			cs[1][i]++ ;
			tmd[1][i] += l[1][i]*sta[i].w ;
			num[1][l[0][i]] -= l[1][i] ;
			ti[1][l[0][i]] -= sta[i].w ;
			wi[1][l[0][i]] -= v ;
			cs[1][l[0][i]]-- ;
			tmd[i][l[0][i]] -= l[1][i]*sta[i].w ;
		}
		FOR(i,1,n,1) 
			num[0][i] += num[0][i-1],ti[0][i] += ti[0][i-1],wi[0][i] += wi[0][i-1] ;
		ROF(i,n,1,1)
			num[1][i] += num[1][i+1],ti[1][i] += ti[1][i+1],wi[1][i] += wi[1][i+1] ;
		FOR(i,1,n,1)
		{
			val[i] = sum-wi[0][i]-wi[1][i]+(i*cs[0][i]-num[0][i])*ti[0][i]-tmd[0][i]+(i*cs[1][i]-num[1][i])*ti[1][i]-tmd[1][i] ;			
		}
		FOR(i,1,n,1) print((sum-val[wh[i]])/2),enter ;
	}
    return 0;
}
